package cn.wolfcode.wolf2w.web.controller;

import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.TravelQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.uitl.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("travel")
public class TravelController {
    @Autowired
    private ITravelService travelService;
    @Autowired
    private IDestinationService destinationService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") TravelQuery qo){
       Page<Travel> page =travelService.query(qo);
       model.addAttribute("page",page);
        //直接返回页面
        return "travel/list";
    }
    /**
     * 通过区域id删除数据
     * @par
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        travelService.delete(id);
        return JsonResult.success();
    }
    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests(){
        //直接返回页面
        return destinationService.lists();
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOUpdate(Travel travel){
        //NoNullStringUitl.getNull(travel.getSequence(),"");
        //直接返回页面
        travelService.saveOUpdate(travel);
       return JsonResult.success();
    }
    //查看功能
    @RequestMapping("/getContentById")
    @ResponseBody
    public JsonResult getContentById(String id){
        Travel travel = travelService.get(id);
        return JsonResult.success(travel.getContent());
    }
    //审核
    @RequestMapping("/changeState")
    @ResponseBody
    public JsonResult changeState(String id,int state){
        travelService.changeState(id,state);
        return JsonResult.success();
    }
}
